const path = require("path")
const express = require("express")
const {
    next
} = require("cheerio/lib/api/traversing")
const app = express()
const staticRoot = path.resolve(__dirname, "../public")

// 文件防盗链
app.use(require("./imgrejectMiddleware.js"))
//日志文件
app.use(require("./vlog"))
//静态私服
app.use(express.static(staticRoot))

app.use(require("./myURLEncode"))

//处理参数格式为x-www
app.use(express.urlencoded({
    extended: true
}))
//处理json
app.use(express.json())

//设置cookie--parser中间件
const cookieParser = require("cookie-parser")
app.use(cookieParser())
app.use(require("./tokenMiddleware"))

//获取博客
app.use("/api/getboke", require("./api/getboke"))
//获取心情说说内容
app.use("/api/getmood", require("./api/mood"))
//获取评论
app.use("/api/getpl", require("./api/pl"))

//用户中间件
app.use("/api/admin", require("./api/admin"))
//文件上传接口
app.use("/api/upload", require("./api/upload"))
//留言接口
app.use("/api/userpl", require("./api/userpl"))

app.use("/api/message", require("./api/message"))
//错误处理中间件
app.use(require("./errorMiddleware"))

let port = 3300
app.listen(port, () => {
    console.log("服务器启动")
})